package com.whq.knowverywell.business.db;

import java.util.HashMap;
import java.util.Map;

/**
 * 跟操作配置表相关的cache虚类
 * @author wanghuaiqiang
 *
 */
public abstract class AbstractTblConfHandler {
	private static final Map<String, String> MAP_CONF = new HashMap<String, String>(0);
	private static boolean cacheInit = false;
	
	protected abstract void allRecordsFromDbToCache();
	
	protected void initCache() {
		if (cacheInit) {
			return ;
		}
		cacheInit = true;
		MAP_CONF.clear();
		allRecordsFromDbToCache();
	}
	
	protected void saveToCache(String key, Object value) {
		if (value != null) {
			MAP_CONF.put(key, value.toString());
		}
	}
	
	protected String getFromCache(String key) {
		if (MAP_CONF.containsKey(key)) {
			return MAP_CONF.get(key);
		}
		return null;
	}
	
	protected void clearCache() {
		MAP_CONF.clear();
		cacheInit = false;
	}
	
	protected void removeFromCache(String key) {
		MAP_CONF.remove(key);
	}
	
}
